var http = require("./mymodal");
var path = require("path");
var data = require("./data/collectById.json");
var entity = require("./mymodal");
var express = require("express");
var mongoose = require("mongoose");
var app = express();
var assert = require("assert");
var options = {
    promiseLibrary: require('bluebird')
};
mongoose.Promise = global.Promise; mongoose.connect("mongodb://localhost:27017/test");
var uri = 'mongodb://localhost/test';
var db = mongoose.createConnection(uri, options);
var Schema = mongoose.Schema;
// db.on('error', console.error.bind(console, 'connection error:'));
// db.once('open', function() {
// 	  // we're connected!
//  });
// var kittySchema = mongoose.Schema({
// 	    userBase: Number,
// 	    effecMonth: String,
// 	    endMonth: String,
// 	    operate: String,
//
// });




// var Kitten = mongoose.model('Kitten', kittySchema);
// var updatess = mongoose.model('editable', kittySchema);

// var kkk = new Kitten({userbase:555,effecmonth:"555",endmonth:"555",operate:"5555" });
// kkk.save();

// var upd = new updatess({userBase:3444,effecMonth:"fdf",endMonth:"ddd",operate:"xxx" });
// upd.save();

// kkk.find(sth);
// function sth(err,data) {
// 	console.log(err);
// }


// var silence = new Kitten({ userBase: '3000' });
// console.log(silence.userBase, "silience 28"); // 'Silence'
// Kitten.find(function (err, kittens) {
// 	  if (err) return console.error(err);
// 	  console.log(kittens,"hey 31 kitten");
// });
http.createServer(function(req, res) {

var kittySchema = mongoose.Schema({
	    userBase: Number,
	    effecMonth: String,
	    endMonth: String,
	    operate: String,

});
    res.writeHead(200, {
        "Content-Type": "text/json"
    });
// kkk.find(function (err, kittens) {
// 	  if (err) return console.error(err);
// 	  console.log(kittens,"here you go ");
// })

var Kitten = mongoose.model('Kittens', kittySchema);
var kkk = new Kitten({userbase:555,effecmonth:"555",endmonth:"555",operate:"5555" });
kkk.save();
// var kkk = new Kitten({});
kkk.find(function (err, kitten) {
	  if (err) return console.error(err);
	  console.log(kkk,"hey 31 kitten");
	
    res.end(JSON.stringify(kkk));
});
    app.use(express.static(path.join(__dirname, 'public')));
}).listen(3333);
// var query = Kitten.findOne({editable: 3000});
// assert.ok(!(query instanceof require('mpromise')));
app.get('/user', function(req, res) {
    res.json({
        msg: 'hello'
    });
    console.log(res);
});
// Band = db.model('band-promises', { name: String });
// Kitten.findOne({ 'userBase':3000 }, function (err, person) {
// 	  if (err) return handleError(err);
// 	  console.log('%s %s is a %s.', Kitten,"yoyo") // Space Ghost is a talk show host.
// })
db.on('open', function() {
    // assert.equal(Band.collection.findOne().constructor, require('bluebird'));
	console.log(3333344444)
});
console.log("server listening on port 3333");
